package com.lang.controller;

import com.lang.entity.Page;
import com.lang.entity.Product;
import com.lang.service.ProductService;
import com.lang.service.impl.ProductServiceImpl;
import com.lang.utils.StrUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/*
 * @Date : 2024/3/13 9:26
 * @Created by Lang
 * @ProjectName : LclShop
 */
@WebServlet("/product")
public class ProductServlet extends BaseServlet {
    private ProductService productService = new ProductServiceImpl();

    //分页展示
    public String page(HttpServletRequest req, HttpServletResponse resp) {
        // 获取参数 tid:查询的类别（手机/手机配件）
        String tid = req.getParameter("tid");
        // 当前页
        String current = req.getParameter("currentPage");
        // 分页展示: 封装Page的实体  将数据集合,当前页,页大小,页总数等进行封装
        Page page = productService.getPage(tid, current);
        req.setAttribute("p", page);

        return StrUtils.FORWARD + "/goodsList.jsp";
    }

    //商品展示
    public String productShow(HttpServletRequest req, HttpServletResponse resp){
        String pid = req.getParameter("pid");
        Product product = productService.getProductById(pid);
        req.setAttribute("goods",product);
        return StrUtils.FORWARD + "/goodsDetail.jsp";
    }
}
